package momo.app.multicast.presence;

import com.thoughtworks.xstream.XStream;

/**
 * Class used to wrap original message before passing it to PubSubManager
 * 
 * @author Sally Ang
 * 
 */
public class Message {
	public static final int TYPE_PRESENCE = 0;
	public static final int TYPE_NORMAL = 1;
	public static final int TYPE_NEW_PEER_JOIN = 2;
	public static final int TYPE_ACKNOWLEDGEMENT = 3;
	private static final String SPLITTER = "<messageType>";

	private int messageType;
	private Object content;

	public Message(int message_type, Object content) {
		this.messageType = message_type;
		this.content = content;
	}

	public int getMessageType() {
		return messageType;
	}

	public Object getContent() {
		return content;
	}

	public String toString() {
		return messageType + SPLITTER + content.toString();
	}

	public String marshall() {
		XStream xstream = new XStream();
		return xstream.toXML(this);
	}
	
	public static Message unmarshall(String xml) {
		XStream xstream = new XStream();
		return (Message)xstream.fromXML(xml);
	}
}
